<extend name="Public/usercenter"/>

<block name="body">
    <div class="uc_communication common_block_border clearfix col-xs-12 pad_0 mt_0" style="min-height:450px;padding-bottom: 20px;">
        <div class="chat_with col-xs-12" style="padding: 12px;padding-top: 13px;">{$talk.title}</div>
        <div class="chat_content col-xs-12">
            <div class="top_link clearfix">
                <a class="return_chat change" href="javascript:void(0);" onClick="javascript:history.back(-1);">返回悄悄话列表</a><a id="doDeleteTalk_list" class="delete_chat change" talk-id="{$talk['id']}">删除悄悄话</a>
            </div>

            <div class="chat_text">
                <php>
                    if(C('TALK_WORDS_COUNT')){
                    $Talk_words_count=C('TALK_WORDS_COUNT');
                    }else{
                    $Talk_words_count=1000;
                    }
                </php>
                <span class="info">发悄悄话给：小B</span><span class="number_info show_num_quick">{$Talk_words_count}</span>

                <div class="talk_box">
                    <div>
                        <textarea class="col-xs-12 form-control" id="tt_content" style="height: 100px"
                                  placeholder="说点什么吧，哪怕就一个逗号~" onfocus="startCheckNum_quick($(this))" onblur="endCheckNum_quick()"></textarea>
                        <div class="clearfix"></div>
                        <div class="do_action">
                            <a href="javascript:" onclick="insertTalkFace($(this))"><img class="weibo_type_icon"
                                                                                         src="__STATIC__/image/bq.png"/></a>
                            <a type="submit" class="btn btn-primary button_change" id="submit-button" onclick="appendMessage()"
                               style="float: right">确定发送</a>
                        </div>
                    </div>
                    <div id="emot_content" class="emot_content"></div>
                </div>
            </div>
            <div class="content">
                <ul id="scrollContainer">
                    <if condition="!$messages"><p class="text-muted" style="text-align: center; font-size: 3em;">
                        <br><br>
                        你们还没有悄悄话记录吆。O(∩_∩)O~
                        <br><br><br>
                    </p></if>
                    <volist name="messages" id="val">
                        <li class="clearfix">
                            <if condition="$val.uid eq is_login()">
                                <div class="me_to_other">
                                    <dl class="dl-horizontal">
                                        <dt><img src="{$val.user.avatar64}" class="img-responsive"></dt>
                                        <dd>
                                            <div class="content_detail clearfix">
                                                <img src="__IMG__/left_link.png">

                                                <div class="talk_info">{$val.content}</div>
                                            </div>
                                            <div class="other_info"><span style="color: #f36119">{$val.user.username}</span>
                                                发布于{$val['create_time']|friendlydate}
                                            </div>
                                        </dd>
                                    </dl>
                                </div>
                                <else/>
                                <div class="other_to_me">
                                    <dl>
                                        <dt><img src="{$val.user.avatar64}" class="img-responsive"></dt>
                                        <dd>
                                            <div class="content_detail clearfix">
                                                <img src="__IMG__/right_link.png">

                                                <div class="talk_info">{$val.content}</div>
                                            </div>
                                            <div class="other_info"><a href="{$val.user.space_url}" class="change" target="_blank">{$val.user.username}</a>
                                                发布于{$val['create_time']|friendlydate}
                                            </div>
                                        </dd>
                                    </dl>
                                </div>
                            </if>
                        </li>
                    </volist>
                </ul>
            </div>
            <div style="width: 100%;text-align: center;">
                {:getPagination($totalCount,50)}
            </div>
        </div>
    </div>
    <script>
        var MID = "{$self.id}";
        var message_id = "{$message_id}";
        var talk_id = "{$talk.id}";
        var username = "{$self.username}"
        var myhead = "{$self.avatar64}";

        function appendMessage() {
            close_face();
            var myDate = new Date();
            $.post(U('Usercenter/Message/postMessage'), {talk_id: talk_id, content: $('#tt_content').val()}, function (msg) {
                if (msg.status) {
                    op_appendMessage(op_fetchMessageTpl({uid: MID, content: msg.content,
                        avatar64: myhead,
                        username: username,
                        left_link: ThinkPHP.ROOT + '/Public/Usercenter/images/left_link.png',
                        create_time: myDate.toLocaleTimeString()}, MID));
                    $('#tt_content').val('');
                    $('#tt_content').focus();
                } else {
                    handleAjax(msg);
                }
            }, 'json');
        }

        $('#tt_content').keypress(function (e) {
            if (e.ctrlKey && e.which == 13 || e.which == 10) {
                appendMessage();
            }
        });

        var ID_setInterval;
        var initTalkNum="{:C('TALK_WORDS_COUNT')}"?"{:C('TALK_WORDS_COUNT')}":1000;
        function checkNum_quick(obj){
            var value=obj.val();
            var value_length=value.length;
            var can_in_num=initTalkNum-value_length;
            if(can_in_num<0){
                value=value.substr(0,initTalkNum);
                obj.val(value);
                value_length=initTalkNum;
            }
            var html=value_length+'/'+initTalkNum;
            $('.show_num_quick').html(html);
        }
        function startCheckNum_quick(obj){
            ID_setInterval=setInterval(function(){
                checkNum_quick(obj);
            },250);
        }
        function endCheckNum_quick(){
            clearInterval(ID_setInterval);
        }
        $('#doDeleteTalk_list').click(function(){
            var talk_id=$(this).attr('talk-id');
            $.post(U('Usercenter/Message/doDeleteTalk_list'),{talk_id:talk_id},function(msg){
                handleAjax(msg);
            },'json')
        });
    </script>
</block>